#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_MainWindow.h"
#include "UiCommon.h"
#include <opencv2/opencv.hpp>
#include "CvMatAndQImage.h"

using namespace cv;
using namespace std;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = Q_NULLPTR);
    ~MainWindow();

protected slots:    
    void on_actionBorder_triggered();
    void on_actionBack_triggered();
    void on_actionEffect1_triggered();    
    void on_actionEffect3_triggered();
    void on_actionImage_triggered();
    void on_actionBatch_triggered();

    void on_actionSaveSetting_triggered();   
    void on_actionSaveAs_triggered();
    void on_actionLoadSetting_triggered();
    void on_actionResetSetting_triggered();   
    void on_actionGlobalSetting_triggered();
    
    void on_btnLoadImage_clicked();
    void on_btnDelete_clicked();
    void on_btnClearImage_clicked();    
    
    void onViewBorder(QStringList list);
    void onViewBack(QStringList list);
    void onViewEffect1(QStringList list);
    void onViewEffect3(QStringList list);
    void on_btnUpdate_clicked();

private:
    void showEvent(QShowEvent *event);
    void loadSetting();
    void saveSetting();
    void settingToUi();
    void uiToSetting();
    void switchToParam(int index);
    void reportError(QString error);
    void updateEffectList();
        
    QRect calcRect(int alignV, int alignH, QSize srcSize, QSize dstSize, QSize offset);
    Rect toCvRect(QRect rc);
    Rect toCvRect(QRectF rc);    
    Mat copyToSmall(Mat dst, Mat src, QRect rc);    
    QString saveFileName(QString filename);

    bool loadImage(QString name,QString filepath, Mat &img);
    bool loadImages(QStringList src_names, vector<Mat> &src_list);
    vector<Mat> cloneImage();

    void addLight(Mat src, Mat dst, Rect rc, int angle, double alpha, int radius);
    void addWater(Mat src, Mat dst, Rect rc);

    bool dealCopy(vector<Mat> &src_list,BorderAddInfo addInfo);
    bool dealAddBorder(bool view);
    bool dealAddBack(bool view);
    Mat dealCut(Effect3Data info);
    Mat dealEffect12(EffectInfo info);
        
    bool dealEffect12Ui(EffectInfo info, bool view);
    bool dealEffect3Ui(Effect3Info info, bool view);
    void dealEffect(QStringList images,bool view);
    void dealEffectSingle(QStringList file_list);

    QString m_proc;
    QString m_error;
    QString m_effect;         
    QVector<QCheckBox*> m_effectBoxs;

    QCheckBox *m_boxAddBorder, *m_boxAddBack, *m_boxEffect3;

    vector<Mat> m_srcBaseImage;
    QStringList m_srcBasePath;

    vector<Mat> m_curImage;
    QStringList m_curPath;     
    QString m_settingPath;

    Ui::MainWindowClass ui;
};
